//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.rain.servlet;

import com.rain.bean.AdminBean;
import com.rain.dao.AdminDao;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet({"/LoginServlet"})
public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public LoginServlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String text = request.getParameter("code");
        String code = (String)request.getSession().getAttribute("code");
        AdminDao userdao = new AdminDao();
        boolean result = userdao.Login_verify(username, password);
        HttpSession session = request.getSession();
        if (code.equalsIgnoreCase(text)) {
            if (result) {
                new AdminBean();
                AdminDao admindao = new AdminDao();
                AdminBean adminbean = admindao.getAdminInfo(username, password);
                session.setAttribute("aid", "" + adminbean.getAid());
                session.setMaxInactiveInterval(6000);
                if (adminbean.getStatus() == 1) {
                    response.sendRedirect("/books/index.jsp");
                } else {
                    response.sendRedirect("/books/admin.jsp");
                }
            } else {
                session.setAttribute("state", "密码错误");
                response.sendRedirect("/books/login.jsp");
            }
        } else {
            session.setAttribute("state", "验证码错误");
            response.sendRedirect("/books/login.jsp");
        }

    }
}
